//
//  XDStatusRetweenView.swift
//  weibo
//
//  Created by lucy on 2016/10/26.
//  Copyright © 2016年 com.huashengHuaSheng. All rights reserved.
//

import UIKit

class XDStatusRetweenView: UIView {
    
    // 记录约束
    var retweetViewCons: Constraint?
    
    var statusViewModel: XDStatusViewModel?{
    
        didSet{
        
            contentLabel.text = statusViewModel?.retweetContentText
            // 卸载约束
            /*
             - 如果配图数组. count > 0 就代表有配图
             - 赋值
             - 显示配图
             - 转发微博的 bottom == 配图的 bottom
             0 如果没有配图
             - 隐藏配图
             - 转发微博的 bottom == 文字的bottom
             */
            // 卸载约束
            retweetViewCons?.uninstall()
            // 有配图
            if (statusViewModel?.statusModel?.retweeted_status?.pic_urls?.count)! > 0 {
                pictureView.picUrls = statusViewModel?.statusModel?.retweeted_status?.pic_urls
                pictureView.isHidden = false
                
                self.snp_makeConstraints { (make) in
                    self.retweetViewCons = make.bottom.equalTo(pictureView).offset(10).constraint
                }
            }else {
                // 没有配图
                pictureView.isHidden = true
                self.snp_makeConstraints { (make) in
                    self.retweetViewCons = make.bottom.equalTo(contentLabel).offset(10).constraint
                }
            }

        }

    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK-设置视图
    private func setupUI(){
//        backgroundColor = RandomColor()
        backgroundColor = UIColor(white: 237/255, alpha: 1)
        addSubview(contentLabel)
        addSubview(pictureView)
        
        contentLabel.snp_makeConstraints { (make) in
            make.top.left.equalTo(10)
        }
        
        pictureView.snp_makeConstraints { (make) in
            //            make.size.equalTo(CGSize(width: 100, height: 100))
            make.left.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
        }
        
        self.snp_makeConstraints { (make) in
            self.retweetViewCons = make.bottom.equalTo(pictureView).offset(10).constraint
        }

    }

    //MARK-懒加载控件
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGray, textSize: XDNormalSizeFont, textContent: "我是一只小小鸟我是一只小小鸟我是一只小小鸟我是一只小小鸟我是一只小小鸟", maxWidth: XDSCREENW-20)

    //配图
    private lazy var pictureView : XDStatusPictureView = {
        let view = XDStatusPictureView()
        view.backgroundColor = self.backgroundColor
        return view

    }()
}

















